﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using QBZ.Evaluation.Models;
using QBZ.Evaluation.Repositories;
using QBZ.Evaluation.Repositories.DataAccess;
using System;
using System.Collections.Generic;
using System.Text;

namespace QBZ.Evaluation.Domains
{                                 
    public class RoleDomain
    {
        private readonly RoleRepository _role;
        private readonly IMemoryCache _cache;

        public RoleDomain(IMemoryCache cache, RoleRepository role)
        {
            _role = role;
            _cache = cache;
        }

        public List<RoleModel> GetAll()
        {
            var result = _cache.GetOrCreate("roleModelAll", (entry) =>
            {
                entry.Priority = CacheItemPriority.NeverRemove;
                return _role.GetAll();
            });
            return result;
        }

        public int AddRole()
        {
            _cache.Remove("roleModelAll");
            return 0;
        }
    }
}
